package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.utils.StringUtils;
import com.laowang.project.system.domain.MyCyhAuthority;
import com.laowang.project.system.service.MyCyhAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyCyhVipAuthorityMapper;
import com.laowang.project.system.domain.MyCyhVipAuthority;
import com.laowang.project.system.service.MyCyhVipAuthorityService;

/**
 * 会员权益Service业务层处理
 *
 * @author laowang
 * @date 2023-06-01
 */
@Service
public class MyCyhVipAuthorityServiceImpl implements MyCyhVipAuthorityService {
    @Autowired
    private MyCyhVipAuthorityMapper myCyhVipAuthorityMapper;

    @Autowired
    private MyCyhAuthorityService myCyhAuthorityService;

    /**
     * 查询会员权益
     *
     * @param id 会员权益ID
     * @return 会员权益
     */
    @Override
    public MyCyhVipAuthority selectMyCyhVipAuthorityById(Integer id) {
        return myCyhVipAuthorityMapper.selectMyCyhVipAuthorityById(id);
    }

    /**
     * 查询会员权益列表
     *
     * @param myCyhVipAuthority 会员权益
     * @return 会员权益
     */
    @Override
    public List<MyCyhVipAuthority> selectMyCyhVipAuthorityList(MyCyhVipAuthority myCyhVipAuthority) {

        return myCyhVipAuthorityMapper.selectMyCyhVipAuthorityList(myCyhVipAuthority);
    }

    /**
     * 新增会员权益
     *
     * @param myCyhVipAuthority 会员权益
     * @return 结果
     */
    @Override
    public int insertMyCyhVipAuthority(MyCyhVipAuthority myCyhVipAuthority) {
        String desc = myCyhVipAuthority.getDesc();
        if (StringUtils.isNotEmpty( desc)){
            MyCyhAuthority myCyhAuthority =new MyCyhAuthority();
            myCyhAuthority.setIntro(desc);
            myCyhAuthorityService.insertMyCyhAuthority(myCyhAuthority);
            myCyhVipAuthority.setAuthorityId(myCyhAuthority.getId());
        }

        return myCyhVipAuthorityMapper.insertMyCyhVipAuthority(myCyhVipAuthority);
    }

    /**
     * 修改会员权益
     *
     * @param myCyhVipAuthority 会员权益
     * @return 结果
     */
    @Override
    public int updateMyCyhVipAuthority(MyCyhVipAuthority myCyhVipAuthority) {
        //MyCyhAuthority myCyhAuthority = myCyhAuthorityService.selectMyCyhAuthorityById(myCyhVipAuthority.getAuthorityId());
        /*if (myCyhAuthority != null && StringUtils.isNotEmpty(myCyhVipAuthority.getDesc())){
            if (!myCyhAuthority.equals(myCyhVipAuthority.getDesc())){
                myCyhAuthority.setIntro(myCyhVipAuthority.getDesc());
                myCyhAuthorityService.updateMyCyhAuthority(myCyhAuthority);
            }
        }*/
        return myCyhVipAuthorityMapper.updateMyCyhVipAuthority(myCyhVipAuthority);
    }

    /**
     * 批量删除会员权益
     *
     * @param ids 需要删除的会员权益ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhVipAuthorityByIds(Integer[] ids) {
        return myCyhVipAuthorityMapper.deleteMyCyhVipAuthorityByIds(ids);
    }

    /**
     * 删除会员权益信息
     *
     * @param id 会员权益ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhVipAuthorityById(Integer id) {
        return myCyhVipAuthorityMapper.deleteMyCyhVipAuthorityById(id);
    }
}
